var _url = '../';
	//初始化页面操作
	$(function(){
    	setTimeout(function(){
            
    		var bedroomSum = $('#bedroomSum').val();
    		var data = $('#shiP').combobox('getData');
    		for(var i=0; i<data.length;i++) {
    			if(data[i].id==bedroomSum){
    				$('#shiP').combobox('select',data[i].id);
    			}
    		}
    		
    		var livingRoomSum = $('#livingRoomSum').val();
    		var data = $('#tingP').combobox('getData');
    		for(var i=0; i<data.length;i++) {
    			if(data[i].id==livingRoomSum){
    				$('#tingP').combobox('select',data[i].id);
    			}
    		}
    		
    		var wcSum = $('#wcSum').val();
    		var data = $('#weiP').combobox('getData');
    		for(var i=0; i<data.length;i++) {
    			if(data[i].id==wcSum){
    				$('#weiP').combobox('select',data[i].id);
    			}
    		}
    		
			var houseType = $('#houseType').val();
    		if(houseType == 2) {
        		var aboveFiveYear = $('#aboveFiveYear').val();
        	    $('input[name="manwu"]').each(function(){
        	    	if (aboveFiveYear != '' && $(this).val() == aboveFiveYear) {
                        $(this).attr("checked",'checked');
        				return;
                    } else if((aboveFiveYear == '' || aboveFiveYear == 0) && $(this).val() == 2){
                    	$(this).attr("checked",'checked');
        				return;
                    }
        	    });
        	    
        	    var onlyOne = $('#onlyOne').val();
        	    $('input[name="weiyi"]').each(function(){
        	    	if (onlyOne != '' && $(this).val() == onlyOne) {
                        $(this).attr("checked",'checked');
        				return;
                    } else if ((onlyOne == '' || onlyOne == 0) && $(this).val() == 2) {
                        $(this).attr("checked",'checked');
        				return;
                    }
        	    });
        	    
        	    getPriceRegion();
    		}
    	},200);	
    });

	function showRemoveHouse() {
        $('#removeHouseDiv').window('open');
        scrollVisible("removeHouseDiv");
        $('#removeHouseDiv').window('move',{top:$(document).scrollTop() + 200});
    }
	
	function scrollVisible(id) {
        $("#" + id).window({
            closed:false,
            modal:true,
            onOpen: function () {
                $(document.body).css({
                    "overflow-x":"hidden",
                    "overflow-y":"hidden"
                });
                return true;
            },
            onClose: function () {
                $(document.body).css({
                    "overflow-x":"auto",
                    "overflow-y":"auto"
                });
                return true;
            }
        });
    }
   
	//打开审核失败浮层
    function showAddFollow() {
        $('#addFollow').window('open');
        scrollVisible("addFollow");
        $('#addFollow').window('move',{top:$(document).scrollTop() + 200});
    }
	//提交失败原因
	function doAddFollow() {
        var followContent = jQuery("#followContent").textbox("getValue");
        if (followContent == "" || jQuery.trim(followContent).length == 0) {
            Iw.Util.errorNoty("请输入失败原因!");
            return;
        }
		
		if (jQuery.trim(followContent).length > 100) {
            Iw.Util.errorNoty("失败原因最多输入100个字!");
            return;
        }
		
		var id = jQuery('#id').val();
		var houseId = jQuery('#houseId').val();
		if(houseId == '') houseId = 0;
		
		var source = jQuery('#source').val();
		if(source == "") source = 1;
		
        var parms = {"failReason":followContent, "id": id, "houseId" : houseId, "source" : source};
        jQuery("#submitFollow").attr("disabled", "disabled");
        jQuery.ajax({
            url:_url + "checkhouse/checkFail.json",
            data:parms,
            type:"post",
            dataTye:"json",
            success: function (result) {
                if (result != null && result.code == "1") {
                    $('#addFollow').window('close');
                    jQuery.messager.alert("提示", "房源委托失败!", "success", function(data) {
	            		window.opener && window.opener.doQuery();
		            	window.close();
	            	});
                } else {
                    Iw.Util.errorNoty(result.message);
                    jQuery("#submitFollow").removeAttr("disabled");
                }
            }
        });
    }
	
	//点击提交
    function onOk() {
        var flag = validatePannelForm();
        if (!flag)
            return;
        jQuery("#submitForm").linkbutton("disable");
        var params = takePannelFormData();

		jQuery.ajax({
	        url:_url + "submitHouseforSelf.json",
	        data:params,
	        type:"post",
	        dataType:"json",
	        async:false,
	        success:function(result) {
	        	
	            if (result.code == 1) {
	            	jQuery.messager.alert("提示", "房源委托成功", "success", function(data) {
	            		window.opener && window.opener.doQuery();
		            	window.close();
	            	});
	            	
	                return;
	            } else if(result.code == 4000011 || result.code == 4000014 || result.code == 4000016) {
	            	jQuery.messager.alert("提示", result.message, "success", function(data) {
	            		window.opener && window.opener.doQuery();
		            	window.close();
	            	});
	            	return;
	            } else {
	                jQuery.messager.alert("警告", result.message, "error", function(data) {
	            		window.opener && window.opener.doQuery();
		            	window.close();
	            	});
	                return;
	            }
	
	        }
	    });
    }
    
//获取价格范围
function getPriceRegion() {
	var cityId = jQuery('#cityId').val();
	var houseType = jQuery('#houseType').val();
	var params = {'ht' : houseType, 'cityId' : cityId};
	jQuery.ajax({
        url:_url + "getPriceRegion.json",
        data:params,
        type:"post",
        dataType:"json",
        async:false,
        success:function(result) {
            if (result.code == 1) {
				$('#minPrice').val(result.data.minPrice);
                $('#maxPrice').val(result.data.maxPrice);
                return;
            } 
        }
    });
}    

//表单验证
function validatePannelForm() {
	var houseType = jQuery('#houseType').val();
    var shoujia = jQuery("#price").numberbox("getValue");
	var maxPrice = $("#maxPrice").val();
	if(maxPrice != "" && houseType == 2) {
		 maxPrice = maxPrice / 10000 ;
	}
	var minPrice = $("#minPrice").val();
	if(minPrice != "" && houseType == 2) {
		minPrice = minPrice / 10000 ;
	}
	
    var mianji = jQuery("#mianji").textbox("getValue");
    var shiP = jQuery("#shiP").combobox("getValue");
    var tingP = jQuery("#tingP").combobox("getValue");
    var weiP = jQuery("#weiP").combobox("getValue");
	
	if (shiP == "") {
        jQuery.messager.alert("错误", "请选择室数!", "error");
        return false;
    }
    if (tingP == "") {
        jQuery.messager.alert("错误", "请选择厅数!", "error");
        return false;
    }
    if (weiP == "") {
        jQuery.messager.alert("错误", "请选择卫数!", "error");
        return false;
    }
	
	if (mianji == "") {
        jQuery.messager.alert("错误", "请输入面积!", "error");
        return false;
    }
	
    if (!/^\d+(.\d{1,2})?$/.test(mianji)) {
        jQuery.messager.alert("错误", "面积请输入数字，请勿超过两位小数!", "error");
        return false;
    }

    if(mianji < 0 || mianji > 10000 ){
    	jQuery.messager.alert("错误", "面积区间在：0-10000平米", "error");
        return false;
    }
	
	if (shoujia == "") {
		if(houseType == 2) {
			jQuery.messager.alert("错误", "请输入正确的售价!", "error");
		} else {
			jQuery.messager.alert("错误", "请输入正确的租金!", "error");
		}
        
        return false;
    }
	shoujia = parseInt(shoujia);
	if (maxPrice != "" && minPrice != "" && (shoujia > maxPrice || shoujia < minPrice)) {
		if(houseType== 2) {
			jQuery.messager.alert("错误", "售价区间在：" + minPrice + "-" + maxPrice + " 万元", "error");
		} else {
			jQuery.messager.alert("错误", "租金区间在：" + minPrice + "-" + maxPrice + " 元/月", "error");
		}
		
        return false;
	}
	
    return true;
}

function takePannelFormData() {
	var cityId = jQuery('#cityId').val();
	var houseType = jQuery('#houseType').val();
	
    var estateId =	jQuery('#estateId').val();
    var subEstateId = jQuery("#subEstateId").val();
   
    var building = jQuery("#building").val();
    var room = jQuery("#room").val();
    
    var price = jQuery("#price").numberbox("getValue");
    var mianji = jQuery("#mianji").textbox("getValue");
    
    var shiP = jQuery("#shiP").combobox("getValue");
    var tingP = jQuery("#tingP").combobox("getValue");
    var weiP = jQuery("#weiP").combobox("getValue");
    var fangdongname = jQuery("#hostName").val();
    var fangdongphone = jQuery("#houstMobile").val();
	
	var checkId = $('#checkId').val();
	
	var estateName = jQuery("#estateName").val();
	var subEstateName = jQuery("#subEstateName").val();

	var aboveFiveYear = jQuery("#aboveFiveYear").val();
	var onlyOne = jQuery("#onlyOne").val();
	if(jQuery("input[name='manwu']").length > 0) {
	    jQuery.each(jQuery("input[name='manwu']"), function(){
	       if ($(this).is(":checked")) {
	    	   aboveFiveYear = $(this).val();
	           return;
	       }
	    });
	    jQuery.each(jQuery("input[name='weiyi']"), function(){
	        if ($(this).is(":checked")) {
	        	onlyOne = $(this).val();
	            return;
	        }
	    });
	}
	
	var source = jQuery("#source").val();
	if(source == "") source = 1;
	
	var gender = jQuery("#gender").val();
	if(gender == "") gender = 0;
	
	var memo = jQuery("#memo").textbox("getValue");

	return {cityId : cityId, houseType : houseType, orderType : 1, source : source, gender : gender, estateId : estateId, subEstateId : subEstateId, building : building, room : room, price : price, spaceArea : mianji, bedroomSum : shiP,
        livingRoomSum : tingP, wcSum : weiP, hostName : fangdongname, houstMobile : fangdongphone, checkId : checkId
        , estateName : estateName, subEstateName : subEstateName, aboveFiveYear : aboveFiveYear, onlyOne : onlyOne, who : 2, memo : memo};
}